﻿using log4net;
using System;
using System.Data;
using System.Reflection;
using System.Web;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using AnyOffice.Components;
using AnyOffice.DAL;
using AnyOffice.Model;
namespace AnyOffice.general.system.workflow.flow_sign
{
    public partial class sign_edit : ModulePage
    {  
        private static ILog  log = LogManager.GetLogger(MethodBase.GetCurrentMethod().DeclaringType);     
 
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!this.Page.IsPostBack)
            {
                int num = (Request.QueryString["sign_id"] == null) ? 0 : int.Parse(Request.QueryString["sign_id"].ToString());
                this.ViewState["SignId"] = num;
                DataTable table = new FlowSignDao().SelectBySignId(base.Conn, num);
                if (table.Rows.Count == 0)
                {
                    this.pnlMain.Visible = false;
                    this.litMessage.Text = base.ShowPrompt("无此印章", "index.aspx");
                    return;
                }
                this.txtSignNo.Text = table.Rows[0]["SignNo"].ToString();
                this.txtSignName.Text = table.Rows[0]["SignName"].ToString();
                if (table.Rows[0]["SignMemo"] != DBNull.Value)
                {
                    this.txtSignMemo.Text = table.Rows[0]["SignMemo"].ToString();
                }
            }
            if (this.Page.IsPostBack)
            {
                this.pnlMain.Visible = false;
                int num2 = Convert.ToInt32(this.ViewState["SignId"].ToString());
                FlowSignDao dao2 = new FlowSignDao();
                FlowSignData flowSignData = new FlowSignData();
                flowSignData.SignId = num2;
                flowSignData.SignNo = Convert.ToInt32(this.txtSignNo.Text);
                flowSignData.SignName = this.txtSignName.Text;
                if (this.txtSignMemo.Text != string.Empty)
                {
                    flowSignData.SignMemo = this.txtSignMemo.Text;
                }
                dao2.Update(base.Conn, flowSignData);
                if (this.fileSign.PostedFile.ContentLength > 0)
                {
                    try
                    {
                        Upload upload = new Upload();
                        upload.OverwriteFile = true;
                        upload.DestinationPath = Server.MapPath("/module/oc/");
                        upload.DestinationFileName = "sign_" + num2.ToString() + ".esp";
                        upload.GetFile(this.fileSign.PostedFile);
                        upload.DoUpload();
                    }
                    catch (Exception exception)
                    {
                        if (log.IsErrorEnabled)
                        {
                            log.Error("", exception);
                        }
                        this.litMessage.Text = base.ShowPrompt("修改电子印章失败！", "index.aspx");
                    }
                }
                this.litMessage.Text = base.ShowPrompt("修改电子印章成功！", "index.aspx");
            }
        }
      
    }
}

